package lianbiao

import (
	tp "hufeng/type-practice"
)

func swapPairs(head *tp.ListNode) *tp.ListNode {
	dummy := &tp.ListNode{Next: head}
	prev := dummy
	for prev.Next != nil && prev.Next.Next != nil {
		a := prev.Next
		b := a.Next
		a.Next = b.Next
		b.Next = a
		prev.Next = b
		prev = a
	}
	return dummy.Next
}

func Size(head *tp.ListNode) (ans int) {
	for head != nil {
		head = head.Next
		ans++
	}
	return
}
